<?php
//--XOA THANH VIEN--
if (isset($_GET['remove']))
{
    $thanhvienid = $_GET ['thanhvienid'];
    $result = mysql_query("DELETE FROM thanhvien where thanhvienid = $thanhvienid;");
    if ($result)
        print '<h2>Xóa thành công !</h2>';
}
?>

<!--FORM THEM THANH VIEN-->
<form action="index.php?nhansu&module=thanhvien" method="post" enctype="multipart/form-data">
<fieldset>
    <legend><h1>Thêm thành viên</h1></legend>
<table>
<tr>
    <td width="100">Phòng ban</td>
    <td width="300"><select name="phongban">
        <?php   $phongban = mysql_query("select * from phongban");
                while ($row = mysql_fetch_array($phongban))
                    print "<option value=$row[phongbanid]>$row[tenphongban]</option>";?></select></td></tr>
<tr><td>Tên thành viên</td>
    <td><input type="text" name="tenthanhvien" /></td></tr>
<tr><td>Chức vụ</td><td><select name="chucvu">
        <?php   $chucvu = mysql_query("select * from chucvu");
                while ($row = mysql_fetch_array($chucvu))
                    print "<option value=$row[chucvuid]>$row[tenchucvu]</option>";?></select></td></tr>
<tr><td></td><td><input class="button" type="submit" name="submit" value="Thêm" /></td></tr>
</table>
</fieldset>
</form>

<?php
//--PHP THEM THANH VIEN--
if (isset($_POST['submit']))
{
    //print_r($_POST);
    $phongban = $_POST['phongban'];
    $tenthanhvien = $_POST['tenthanhvien'];
    $chucvu = $_POST['chucvu'];
    $sql = "INSERT INTO thanhvien(phongban, tenthanhvien, chucvu) VALUES ('$phongban','$tenthanhvien', '$chucvu') ";
    $result = mysql_query($sql);
    if ($result)
        print '<h2>Thành công!</h2>';
}
?>
<!--HIEN THI CAC THANH VIEN-->
<fieldset>
<legend><h1>Danh sách thành viên trong tổ chức</h1></legend>
<table width="695" border="0">
    <tr>
        <td width="100"><b>ID</b></td>
        <td width="300"><b>Phòng ban</b></td>
        <td width="300"><b>Tên thành viên</b></td>
        <td width="300"><b>Chức vụ</b></td>
        <td width="300"><b>Sửa / Xóa</b></td>
    </tr>

    <?php
        $thanhvien = mysql_query("select * from thanhvien");
        while ($row = mysql_fetch_array($thanhvien))
        {
    ?>
    <tr>
        <td width="100"><?php print "$row[thanhvienid]"; ?> </td>
        <td width="300"><?php $phongban = mysql_query("select * from phongban where phongbanid = $row[phongban]");
                                while ($row2 = mysql_fetch_array($phongban)) print "$row2[tenphongban]";?> </td>
        <td width="300"><?php print "$row[tenthanhvien]"; ?> </td>
        <td width="300"><?php $chucvu = mysql_query("select * from chucvu where chucvuid = $row[chucvu]");
                                while ($row3 = mysql_fetch_array($chucvu)) print "$row3[tenchucvu]";?> </td>
        <td width="300">
        <a href="index.php?nhansu&module=thanhvien&thanhvienid=<?php print "$row[thanhvienid]"; ?>&edit">Sửa</a> /
        <a href="index.php?nhansu&module=thanhvien&thanhvienid=<?php print "$row[thanhvienid]"; ?>&remove" onclick="return confirm('Muốn xóa thật ko?')" >Xóa</a>
        </td>
    </tr>
    <?php 
        }
    ?>
</table>
</fieldset>
